package com.starbaba.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;



public class CarRegion {
	
	public static Map<String,String> city2num = new HashMap<String,String>();
	
	public static Map<String,String> num2city = new HashMap<String,String>();
	
	public static Map<String,String> num2province = new HashMap<String,String>();
	
	public static Map<String,String> province2city = new HashMap<String,String>();
	
	private static String fileName = "car_region.txt";
	
	public static void init() {
		String path = CarRegion.class.getResource("/").toString();
		String rootPath = new File(path.substring(5)).getAbsolutePath();
		File file = new File(rootPath + File.separator + fileName);
		BufferedReader reader = null;
		FileReader fileReader = null;
		try {
			fileReader = new FileReader(file);
			reader = new BufferedReader(fileReader);
			String line = reader.readLine();
			String[] list;
			while (line != null) {
				line = line.trim();
				list = line.split("\\|");
				city2num.put(list[1], list[0]);
				num2city.put(list[0], list[1]);
				
				line = reader.readLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {

			try {
				if (reader != null) {
					reader.close();
				}
				if (fileReader != null) {
					fileReader.close();
				}
				
			} catch (IOException e) {
				e.printStackTrace();
			}

		}

	}
	
	static
	{
		init();
	}

}
